from django.contrib import admin

from MyModel.models import Test, Contact, Tag


# Register your models here.

class TagInline(admin.TabularInline):
    """
    Contact页面内嵌Tag页面
    """
    model = Tag


class ContactAdmin(admin.ModelAdmin):
    """
    定义了一个 ContactAdmin 类，用以说明管理页面的显示格式
    """
    inlines = [TagInline]  # inlines属性
    list_display = ('id', 'name', 'age', 'email')  # list_display属性
    # Add页面的显示字段
    fieldsets = (
        ['Main', {
            'fields': ('name', 'email'),
        }],
        ['Advance', {
            'classes': ('collapse',),  # css
            'fields': ('age',),
        }]
    )


class TagAdmin(admin.ModelAdmin):
    list_display = ('id', 'tag_name', 'contact_id')
    # Add页面的显示字段
    fieldsets = (
        ['Tag', {
            'fields': ('tag_name', 'contact')
        }],
        # ['Advance', {
        #     'classes': ('collapse',),  # css
        #     'fields': ('age',),
        # }]
    )


class TestAdmin(admin.ModelAdmin):
    list_display = ('id', 's_name', 's_birth', 's_sex', 's_create')
    # Add页面的显示字段
    fields = ('s_name', 's_birth', 's_sex')
    # 搜索栏
    search_fields = ('s_name',)


# 页面注册
admin.site.register(Contact, ContactAdmin)
admin.site.register(Tag, TagAdmin)
admin.site.register(Test, TestAdmin)
